import Base from 'models/base';

import SystemUtil from 'utils/systemUtil';

export default class CouponTaoDetail extends Base {
  constructor(coupon) {
    super();

    this.itemId = coupon.itemid;
    this.activityId = coupon.activityid;
    this.title = coupon.itemshorttitle;
    this.pic = `${coupon.itempic}_800x800.jpg`;
    this.desc = coupon.couponexplain;

    this.money = this.getNumberData(coupon, 'couponmoney');
    this.total = this.getNumberData(coupon, 'couponnum');
    this.count = this.getNumberData(coupon, 'couponsurplus');
    this.price = this.getNumberData(coupon, 'itemprice');
    this.couponPrice = this.getNumberData(coupon, 'itemendprice');

    this.couponStartTime = this.getNumberData(coupon, 'couponstarttime') * 1000;
    this.couponEndTime = this.getNumberData(coupon, 'couponendtime') * 1000;
    this.activityStartTime = this.getNumberData(coupon, 'start_time') * 1000;
    this.activityEndTime = this.getNumberData(coupon, 'end_time') * 1000;

    let couponDescPic = coupon.itempic_copy;
    if (SystemUtil.isEmpty(couponDescPic)) {
      couponDescPic = '';
    } else {
      couponDescPic = `http://img.haodanku.com/${couponDescPic}`;
    }
    this.couponDescPic = couponDescPic;

    let couponDescText = coupon.guide_article;
    if (SystemUtil.isEmpty(couponDescText)) {
      couponDescText = '';
    }
    this.couponDescText = couponDescText;
  }

  getNumberData(coupon, field) {
    let value = coupon[field];
    if (SystemUtil.isEmpty(value)) {
      return '';
    }

    value = Number(value);
    return value;
  }
}
